#include "mysignalslot.h"
#include <QDebug>
#include <QThread>

MySignalSlot::MySignalSlot(QObject *parent) : QObject(parent)
{
    qDebug() << "connect signal slot";
//    connect(this, SIGNAL(myEvent()), this, SLOT(onMyEvent())); //默认是同步阻塞模式 AutoConnection
//    connect(this, SIGNAL(myEvent()), this, SLOT(onMyEvent()), Qt::ConnectionType::DirectConnection); // sync
    connect(this, SIGNAL(myEvent()), this, SLOT(onMyEvent()), Qt::ConnectionType::QueuedConnection); // async
//    connect(this, SIGNAL(myEvent()), this, SLOT(onMyEvent()), Qt::ConnectionType::UniqueConnection); // sync
//    connect(this, SIGNAL(myEvent()), this, SLOT(onMyEvent()), Qt::ConnectionType::BlockingQueuedConnection); // ??

}

void MySignalSlot::testEmitEvent()
{
    qDebug() << "emiting";
    emit myEvent();
    qDebug() << "emitted";
    qDebug() << "sleeping";
    QThread::sleep(5);
    qDebug() << "sleep finished";
}

void MySignalSlot::onMyEvent()
{
    qDebug() << "onMyEvent";
    qDebug() << "sleeping";
    QThread::sleep(3);
    qDebug() << "sleep finished";
}
